const goodsModel = require("../models/goods_model")
const Result = require("../beans/result")

// 添加商品
function Addgoodslist(goods, callback) {

    goodsModel.createGoods(goods, (err, data) => {
        console.log("dataddatdat", data);
        if (err) {
            callback(new Result(null, data, "添加商品数据失败", 401))
        } else {
            callback(new Result(err, {}, "添加商品数据成功", 200))
        }
    })
}
function getAllgoodslist(goods, callback) {

    goodsModel.getAllGoods(goods, (err, data) => {
        console.log("dataddatdat", data);
        if (err) {
            callback(new Result(null, data, "查询商品数据失败", 401))
        } else {
            callback(new Result(err, data, "查询商品数据成功", 200))
        }
    })
}
// 修改商品
function putgoods(goodslist, callback) {

    goodsModel.updataGoods(goodslist, (err, data) => {
        console.log("dataddatdat", data);
        if (err) {
            callback(new Result(null, data, "修改商品数据失败", 401))
        } else {
            callback(new Result(err, {}, "修改商品数据成功", 200))
        }
    })
}
//商品下架Unsalable
function putgoodsUnsalable(goodslist, callback) {

    goodsModel.updataGoodsUnsalable(goodslist, (err, data) => {
        console.log("dataddatdat", data);
        if (err) {
            callback(new Result(null, data, "修改商品下架数据失败", 401))
        } else {
            callback(new Result(err, {}, "修改商品下架数据成功", 200))
        }
    })
}
module.exports={
    Addgoodslist,
    putgoods,
    putgoodsUnsalable,
    getAllgoodslist
}